﻿@model Fap.AspNetCore.ViewModel.JqGridViewModel
<fap-grid id="payitem" grid-model="Model" wrapper="modal-body" auto-width="true"></fap-grid>
<script>
    function AddPayItem(caseUid) {
        var dialog = bootbox.dialog({
            title: $.lang("add_payitem", "添加薪资项"),
            message: ' <select multiple="multiple" size="10" id="duallistbox_payitems" name="duallistbox_payitems"></select>',
            buttons: {
                success: {
                    label: $.lang("ok", "确定"),
                    className: "btn-primary",
                    callback: function () {
                        var vals = $("#duallistbox_payitems").val();
                        if (vals ===null) {
                            bootbox.alert($.lang("select_item_empty", "选择项为空"))
                        } else {
                            $.post("@Url.Content("~/Payroll/Api/PayItems")", { payItems: vals, caseUid: caseUid }, function (rv) {
                                if (rv.success == true) {
                                    refreshPayItems();
                                } else {
                                    bootbox.alert(rv.msg);
                                }
                            })
                        }
                    }
                },
                cancel: {
                    label: $.lang("cancel", "取消"), className: "btn-default"
                }
            }
        });
        dialog.init(function () {
            $.get("@Url.Content("~/Payroll/Api/PayItems/")" + caseUid, function (rv) {
                if (rv.success) {
                    $("#duallistbox_payitems").empty();
                    $.each(rv.data, function (i, d) {
                        let strSel='';
                        if (d.isSelected === true) {
                            strSel = 'selected = "selected"';
                        }
                        $("#duallistbox_payitems").append("<option value='" + d.fid + "' " + strSel + ">" + d.colComment + "</option>");
                    })
                     $('#duallistbox_payitems').bootstrapDualListbox({
                        nonSelectedListLabel: '<span class="text-primary h5">' + $.lang("all_payitem", "所有薪资项") + '</span> ',
                        selectedListLabel: '<span class="text-primary h5">' + $.lang("selected_payitem", "选中薪资项") + '</span> ',
                         preserveSelectionOnMove: 'moved',
                         moveOnSelect: true,

                    });
                }
            })
        })
    }
    function generatePayItem(caseUid) {
        var index= layer.load();
        $.post(basePath + "/Payroll/Api/CreatePayCase", { caseUid: caseUid }, function (rv) {
            if (rv.success) {
                $.msg(rv.msg);
            } else {
                bootbox.alert(rv.msg);
            }
            layer.close(index);
        })
    }
    function setPayrollItemShow(caseUid) {
        var dialog = bootbox.dialog({
            title: $.lang("show_payitem", "薪资条项"),
            message: ' <select multiple="multiple" size="10" id="duallistbox_payrollitems" name="duallistbox_payrollitems"></select>',
            buttons: {
                success: {
                    label: $.lang("ok", "确定"),
                    className: "btn-primary",
                    callback: function () {
                        var vals = $("#duallistbox_payrollitems").val();
                        if (vals ===null) {
                            bootbox.alert($.lang("select_item_empty", "选择项为空"))
                        } else {
                            $.post("@Url.Content("~/Payroll/Api/PayrollItem")", { payItems: vals, caseUid: caseUid }, function (rv) {
                                if (rv.success == true) {
                                    refreshPayItems();
                                } else {
                                    bootbox.alert(rv.msg);
                                }
                            })
                        }
                    }
                },
                cancel: {
                    label: $.lang("cancel", "取消"), className: "btn-default"
                }
            }
        });
        dialog.init(function () {
            $.get("@Url.Content("~/Payroll/Api/PayrollItems/")" + caseUid, function (rv) {
                if (rv.success) {
                    $("#duallistbox_payrollitems").empty();
                    $.each(rv.data, function (i, d) {
                        let strSel='';
                        if (d.showCard === 1) {
                            strSel = 'selected = "selected"';
                        }
                        $("#duallistbox_payrollitems").append("<option value='" + d.fid + "' " + strSel + ">" + d.columnUidMC + "</option>");
                    })
                    $('#duallistbox_payrollitems').bootstrapDualListbox({
                        nonSelectedListLabel: '<span class="text-primary h5">' + $.lang("all_payitem", "所有薪资项") + '</span> ',
                        selectedListLabel: '<span class="text-primary h5">' + $.lang("selected_payrollitem", "薪资条项") + '</span> ',
                        preserveSelectionOnMove: 'moved',
                        moveOnSelect: true,

                    });
                }
            })
        })
    }
    function refreshPayItems() {
        reloadGrid("grid-payitem");
    }

</script>